//
//  VKMeMessageModel.m
//  V-Learn
//
//  Created by liubo on 2019/1/11.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "VKMeMessageModel.h"

@implementation VKMeMessageModel
- (NSString *)createDate{
    NSString *dateS = [[_createDate stringByReplacingOccurrencesOfString:@"T" withString:@" "] substringToIndex:19];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"YYYY-MM-dd HH:mm:ss";
    NSDate *date = [formatter dateFromString:dateS];
    
    return [self getDateDisplayString:[date timeIntervalSince1970] * 1000];
}
-(NSString *)getDateDisplayString:(long long) miliSeconds{
//    NSLog(@"-时间戳---%lld_----",miliSeconds);
    
    NSTimeInterval tempMilli = miliSeconds;
    NSTimeInterval seconds = tempMilli/1000.0;
    NSDate *myDate = [NSDate dateWithTimeIntervalSince1970:seconds];
    
    NSCalendar *calendar = [ NSCalendar currentCalendar ];
    int unit = NSCalendarUnitDay | NSCalendarUnitMonth |  NSCalendarUnitYear ;
    NSDateComponents *nowCmps = [calendar components:unit fromDate:[ NSDate date ]];
    NSDateComponents *myCmps = [calendar components:unit fromDate:myDate];
    
    NSDateFormatter *dateFmt = [[NSDateFormatter alloc ] init ];
    
    //2. 指定日历对象,要去取日期对象的那些部分.
    NSDateComponents *comp =  [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitWeekday fromDate:myDate];
    
    if (nowCmps.year != myCmps.year) {
        dateFmt.dateFormat = @"yyyy-MM-dd hh:mm";
    } else {
        if (nowCmps.day==myCmps.day) {
            dateFmt.AMSymbol = @"上午";
            dateFmt.PMSymbol = @"下午";
            dateFmt.dateFormat = @"aaa hh:mm";
            
        } else if((nowCmps.day-myCmps.day)==1) {
            dateFmt.dateFormat = @"昨天 HH:mm";
        } else {
            if ((nowCmps.day-myCmps.day) <=7) {
                switch (comp.weekday) {
                    case 1:
                        dateFmt.dateFormat = @"周日 HH:mm";
                        break;
                    case 2:
                        dateFmt.dateFormat = @"周一 HH:mm";
                        break;
                    case 3:
                        dateFmt.dateFormat = @"周二 HH:mm";
                        break;
                    case 4:
                        dateFmt.dateFormat = @"周三 HH:mm";
                        break;
                    case 5:
                        dateFmt.dateFormat = @"周四 HH:mm";
                        break;
                    case 6:
                        dateFmt.dateFormat = @"周五 HH:mm";
                        break;
                    case 7:
                        dateFmt.dateFormat = @"周六 HH:mm";
                        break;
                    default:
                        break;
                }
            }else {
                dateFmt.dateFormat = @"MM-dd hh:mm";
            }
        }
    }
    return [dateFmt stringFromDate:myDate];
}
@end
